package com.hnust.dao;

import com.hnust.domain.College;
import com.hnust.domain.record.CollegeRecord;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 *创建人：张汝往，高富昌
 *创建时间：2020/10/6
 *描述：学院管理DAO
 */
import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface CollegeDao {

    //根据学院Id获取学院名字
    @Select("select name from college where col_id=#{collegeId}")
    @ResultType(String.class)
    public String findNameByCollegeId(String collegeId);

    //获取所有学院信息
    @Select("select * from college")
    @ResultType(College.class)
    public List<College> getCollegeList();

    //获取学院及管理员信息
    @Select("SELECT c.col_id collegeId,c.name name,d.col_adm_id colAdmId,d.name admin FROM `college` c left JOIN college_admin d ON c.col_id=d.col_id GROUP BY c.col_id")
    @ResultType(CollegeRecord.class)
    public List<CollegeRecord> getAllCollegeList();

    //插入学院
    @Insert("insert into college (col_id,name) values (#{collegeId},#{name})")
    @ResultType(Boolean.class)
    Boolean addCollegeById(String collegeId,String name);

    //根据学院Id删除学院
    @Delete("delete from college where col_id=#{collegeId}")
    @ResultType(Integer.class)
    Boolean deleteCollegeById(String collegeId);

    @Select("select col_id from college where col_num=#{num}")
    String getCollageIdByNum(String num);

    /*
     * @Author Tonited
     * @Description //TODO 根据学院名获取学院Id
     * @Date 15:35 2020/11/12
     * @Param
     * @return String
     **/
    @Select("select col_id from college where name=#{name}")
    @ResultType(String.class)
    String getCollageIdByName(String name);

    @Select("SELECT col_id collegeId,name,col_adm_id colAdmId,account,password FROM college_admin WHERE col_adm_id=#{colAdmId}")
    @ResultType(Map.class)
    Map<String,String> getCollageAdminInfo(String colAdmId);

}
